<? 
	if(isset($_POST['btngo']))
	{
		require("required/dbconnect.php");
		$pageno=$_POST['pageno'];
		header("Location:order_view.php?page=$pageno");
	}
	
			
	$title="View all offline sales"; 
	$pageid="1";
	$accessid="a00";
	
	require("required/dbconnect.php"); 
	require("required/function.php");
	require("required/header.php");
	
	checkAccess("allow_branch_sales_view",1);
	
?>
<script src="required/js/jquery-1.4.2.js"></script>
<script src="required/js/common_javascript.js"></script>
<?	
		
	if(!empty($_GET['action']))
	{
		switch($_GET['action'])
		{
			case 1:
				$msg="<div class='dw_success'>Data inserted</div>";
				break;
			case 2:
				$msg="<div class='dw_success'>Data Deleted</div>";
				break;
			case 3:
				$msg="<div class='dw_success'>Data Updated</div>";
				break;	
			default:
				$msg="";
				break;
		}
		echo "<script>displayMsg('divMsg')</script>";	
	}else{
		$msg="";
	}
	
	

		
	if(empty($_GET['page']))
	{
		$page="1";
	}
	else
	{
		$page=$_GET['page'];
	}
	
	$totalperpage=30;

	$from=($page-1)*$totalperpage;	
	if($_SESSION['branch_id']==0)
	{
		$get_purchase=mysql_query("select * from os_offline_purchase order by created_datetime desc limit $from,$totalperpage")or die(mysql_error());
		$get_total=mysql_query("select count(*) as result from os_offline_purchase")or die(mysql_error());		
	}
	else
	{
		$get_purchase=mysql_query("select * from os_offline_purchase where created_branch_id=".$_SESSION['branch_id']." order by created_datetime desc limit $from,$totalperpage")or die(mysql_error());
		$get_total=mysql_query("select count(*) as result from os_offline_purchase where created_branch_id=".$_SESSION['branch_id'])or die(mysql_error());
	}
	
?>
<table width="100%">

<?
	$count=mysql_result($get_total,0,"result");


	
?>
<td align="left" valign="top">
	<div class="title">View All Offline Purchase</div>
     <div id="divMsg"><?= $msg ?></div>
	<table width="100%" cellpadding="2" cellspacing="1" >
		
		<? if(mysql_num_rows($get_purchase)==0){ ?>
		<tr>
		 <td height="200" valign="middle" colspan="8" align="center">
			<font color="#FF0000">- No order found -</font><br>
		 </td>
		</tr>
		<? }else{ ?>
		<tr>
            <td width="100%" colspan="6" align="left"><br><br>
                <table width="100%" cellpadding="0" cellspacing="0" >
                    <td width="51%" height="45">
                  	 <?= getPaging($totalperpage,$count,$page,"offline_purchase_view_all.php?param=ntg") ?>
                    
                    </td>
                
              </table>
            </td>
        </tr>
		<tr>
        	<td width="100%" colspan="4">
            <table class="solidborder" width="100%" >
              <tr class="table_header">
                <td width="17%">Receipt Number</td>
                
                <td width="20%">Total Amount(RM)</td>
                <td width="14%">Buyer Email</td>
                <td width="18%">Purchase Date</td>
                <td width="12%">Created By</td>
              <td width="12%">Action</td>
              
              </tr>
		<?
			$no=$from+1;
			while($c=mysql_fetch_array($get_purchase))
			{
				if($no%2==0)
				{
					$class1="table_item_even";
					$class2="table_item_odd";
				}
				else
				{
					$class1="table_item_odd";
					$class2="table_item_even";
				}
				
				
					
						
				
				
		?>	
		 <tr height="30" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover'" 
                            onmouseout="this.className='<?= $class1 ?>'">
			<td><a href="offline_purchase_view_full.php?id=<?= $c['id'] ?>"><?= $c['receipt_number'] ?></a></td>
            <td align="right"><font color="#FF0000"><?= number_format($c['amount'],2) ?></font></td>
            <td><?= $c['email'] ?></td>
            <td><?= $c['purchase_date'] ?></td>
            <td><?= getDataById("os_user","user_id","id",$c['created_by']) ?></td>
             <td align="center">
                
            <a href="offline_purchase_view_full.php?id=<?= $c['id'] ?>"><img src="images/icons/view_icon.gif" border="0"></a>
			
			<?
				if(checkAccess("allow_branch_sales_delete",1))
				{
			?>
            <a href="offline_purchase_delete.php?id=<?= $c['id'] ?>">
                <img src="images/icons/delete.gif" border="0">
            </a>
            <? } ?>    
                
                
            </td>
            
		
		</tr>
		<? $no++;}
		?>
		</table>
		</td>
		<?
		
		} ?>
		
	</table>
	</td>
</table>

<? require("required/footer.php"); ?>

